package com.it.chinasoft.controller;

import com.it.chinasoft.pojo.Manager;
import com.it.chinasoft.serviceimpl.ManagerSerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;


/*整合thymeleaf,mybatis*/
/*注意此处是restcontroller,而不是controller*/
@RestController
public class HelloController {

    @Autowired
    ManagerSerImpl msi;

    @RequestMapping(value="/hello")
    public String printHello(){
        return "Hello World, from Springboot";
    }

    /*函数功能：根据特定值显示类的名字，输入key，默认输入1，但可以修改编号，输出名字*/
   @RequestMapping(value="/manager",method = RequestMethod.GET)
    public ModelAndView showManagers(HttpServletRequest request, @RequestParam(value="mnumber",defaultValue="1",required=false) int mgr_number){
        ModelAndView mv=new ModelAndView();
       System.out.println("Message from Function showManagers Class HelloController:mnumber="+mgr_number);
        Manager mgr=msi.query_Sole_Manager(mgr_number);
        mv.addObject("mgr_info",mgr);
        System.out.println("new created sentences");
        System.out.println(mgr);
        return mv;
    }

}
